<?php

// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 订单商品ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   create by allen.qiang
 */
//加载订单商品查询类
quanli_include('module/base/bill/billSearch.class.php');
//加载订单商品生产表查询类
quanli_include('module/base/bill/billGoodsProduct.class.php');

//查询配送站类
quanli_require('module/base/system/sysDistribution.class.php');

//查询配送员类
quanli_require('module/base/system/sysDistributionTechnician.class.php');

class ajax_voucherGoods {

    public function execute() {

        global $G_PGLOB;

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ($_REQUEST['operFlg']) {

                case 1:
                    $this->searchVoucherGoods();      //查询订单商品生产信息
                    break;

                case 2:
                    $this->searchBillGoodsInfo();      //质检入库 上车扫描 下车扫描操作
                    break;

                case 3:
                    $this->showDetail();     //订单详情
                    break;

                case 4:
                    $this->execOutBus();     //生产or入库后直接 下车扫描
                    break;

                case 5:
                    $this->writeBillGoodsProductError();     //生产or入库后直接 下车扫描 点击取消操作
                    break;

                case 6:
                    $this->writeBillGoodsOperateForget();     //跳流程操作下车扫描 信息记录到订单商品漏操作记录表bill_goods_operate_forget
                    break;
                case 7:
                    $this->notePrompt();     //短信提示站长
                    break;
                // add by 20141030 allen.qiang FUN-BK-0016-订单下错站处理 start
                case 8:                    //查询当天非本站点订单操作记录
                    $this->bill_downBuscan_miss();
                    break;
                case 9:                    //下错站发送短信给站长
                    $this->send_message();
                    break;
                case 10:                   //下错站发送邮件给站长
                    $this->send_emails();
                    break;
                // add by 20141030 allen.qiang FUN-BK-0016-订单下错站处理 end
                default:
                    $G_PGLOB->smarty->assign('msg', '参数错误，请审核后再操作');
                    $G_PGLOB->smarty->display('comm/error.tpl');

            }
        }
    }

    /**
     * 查询订单商品生产信息
     */
    private function searchVoucherGoods() {
        global $G_PGLOB;
        //实例化入库单类
        $billGoodsProduct = new billGoodsProduct();

        if(!isset($_REQUEST['userFlg']) || !is_numeric($_REQUEST['userFlg'])){
            returnJsonData('参数错误','400');
        }

        if(!isset($_REQUEST['formValues']['send_date']) || empty($_REQUEST['formValues']['send_date'])){
            returnJsonData('缺少参数','400');
        }

        //查询条件选择了城市、配送站 则根据选择的城市、配送站查询
        if( isset($_REQUEST['formValues']['cityID']) && is_numeric($_REQUEST['formValues']['cityID']) && isset( $_REQUEST['formValues']['distribution_id']) && is_numeric($_REQUEST['formValues']['distribution_id'])){
            $_REQUEST['formValues']['cityID'] = $_REQUEST['formValues']['cityID'];
            $_REQUEST['formValues']['distribution_id'] = $_REQUEST['formValues']['distribution_id'];

            //查询条件选择了城市、没有选择配送站 则根据选择的城市、当前登录用户权限下的配送站查询
        }else if(isset($_REQUEST['formValues']['cityID']) && is_numeric($_REQUEST['formValues']['cityID']) && !isset( $_REQUEST['formValues']['distribution_id']) || !is_numeric($_REQUEST['formValues']['distribution_id']) ){
            $_REQUEST['formValues']['cityID'] = $_REQUEST['formValues']['cityID'];
            global $G_SHOP;
            $PS_LOGIN_SESSION =$G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

            $distribution_id_array = $PS_LOGIN_SESSION['distribution'];//权限下的配送站id数组

            if( count($distribution_id_array) > 1){

                $distribution_id_arg = implode( ',',$distribution_id_array );

                $_REQUEST['formValues']['extend'] = ' AND distribution_id IN ('.$distribution_id_arg.')';

            }else{
                $_REQUEST['formValues']['distribution_id'] = $distribution_id_array[0];

            }

            //查询条件没有选择城市、没有选择配送站 则根据选择的城市、当前登录用户权限下的城市、配送站查询
        }else{
            global $G_SHOP;
            $PS_LOGIN_SESSION =$G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

            $distribution_id_array = $PS_LOGIN_SESSION['distribution'];//权限下的配送站id数组

            if( count($distribution_id_array) > 1){

                $distribution_id_arg = implode( ',',$distribution_id_array );

                $_REQUEST['formValues']['extend'] = ' AND distribution_id IN ('.$distribution_id_arg.')';

            }else{
                $_REQUEST['formValues']['distribution_id'] = $distribution_id_array[0];

            }
        }


        //add by allen.qiang 20141104 FUN-BK-0014 代付单跳流程 ---start
        $_REQUEST['formValues']['G_DFD_SKU'] = "DFD";//是不是代付单跳流程查询
        //add by allen.qiang 20141104 FUN-BK-0014 代付单跳流程 ---end

        //调用分组查询订单商品生产表方法
        $billGoods_array = $billGoodsProduct->searchbillGoodsProductGroup($_REQUEST['formValues']);

        if ($billGoods_array) {
            returnJsonData('ok','200',$billGoods_array);
        }else{
            returnJsonData('暂无对应订单商品生产数据','400');
        }

    }


    /**
     * 质检入库 上车扫描 下车扫描操作
     */
    private function searchBillGoodsInfo() {

        global $G_PGLOB;

        if(!isset($_REQUEST['userFlg']) || !is_numeric($_REQUEST['userFlg'])){
            returnJsonData('参数错误','400');
        }

        if(!isset($_REQUEST['bill_goods_no']) || empty($_REQUEST['bill_goods_no'])){
            returnJsonData('缺少参数','400');
        }

        if(!isset($_REQUEST['formValues']['send_date']) || empty($_REQUEST['formValues']['send_date'])){
            returnJsonData('缺少参数','400');
        }

        //实例化订单商品查询类
        $billGoodsProduct = new billGoodsProduct();

        //订单商品流水号参数
        $arg_array = array(
            'bill_goods_no'=>$_REQUEST['bill_goods_no']
        );

        //调用查询订单商品生产表方法
        $billGoods_array = $billGoodsProduct->searchBillGoodsInfo( $arg_array );

        //调用查询订单商品表方法
        $billGoods = $billGoodsProduct->searchBillGoods( $arg_array );

        if( !$billGoods ){
        	//mod by yim.hu 20141119 FUN-BK-0032 返回报错编号4000为查询不到流水号方便判断 ---start
            	//returnJsonData('暂无该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单商品数据','400');
        	returnJsonData('暂无该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单商品数据','4000');            
            //mod by yim.hu 20141119 FUN-BK-0032 返回报错编号4000为查询不到流水号方便判断 ---end
        }

        $args_array = array(
            'bill_no'=>$billGoods[0]['bill_no']
        );

        //调用查询订单商品表 获得订单含有多少个商品

        //mod by allen.qiang 20141104 FUN-BK-0015 代付单跳流程 ---start
            // $billGoods_count = $billGoodsProduct->searchBillGoods( $args_array );
            // $billGoods_count = count( $billGoods_count );
        $bill_goods_array= $billGoodsProduct->searchBillGoods( $args_array );
        $billGoods_count = count( $bill_goods_array );
        //mod by allen.qiang 20141104 FUN-BK-0015 代付单跳流程 ---end

        //$billGoods_array[0]['billGoods_count'] = $billGoods_count;

        //获得配送站信息
        if( $billGoods_array ){
            $distribution_id = $billGoods_array[0]['distribution_id'];

            //实例化配送站类
            $sysDistribution = new sysDistribution();
            if( $distribution_id > 0 ){
                $arg_array = array(
                    'distribution_id'=>$distribution_id
                );
                $sysDistribution_array = $sysDistribution->search( $arg_array );

                if( $sysDistribution_array ){
                    $audio = $sysDistribution_array[0]['audio'];//配送站音频地址
                    $billGoods_array[0]['distribution_audio'] = $audio;
                }
            }
        }

        if( $billGoods_array ){

            //下车扫描判断配送站权限
            if( $_REQUEST['userFlg'] == 3){

                global $G_SHOP;
                $PS_LOGIN_SESSION =$G_SHOP->sessionCache_get('PS_LOGIN_SESSION');

                $distribution_id_array = $PS_LOGIN_SESSION['distribution'];//权限下的配送站id数组

                if( !in_array($billGoods_array[0]['distribution_id'],$distribution_id_array) ){

                     //add by 20141030  allen.qiang FUN-BK-0016-订单下错站处理start

                    //发送短信start
                    //实例化配送站设置类
                    $sysDistribution=new sysDistribution();
                    $arg_array=array(
                        'distribution_id'=>$billGoods_array[0]['distribution_id']
                    );
                    $sys_query=$sysDistribution->search($arg_array);
                     //查询订单编号
                    $bill_goods_product_sql='SELECT bill_code FROM bill_goods_product where bill_goods_no= ?';
                    $bill_code=$G_PGLOB->DBCA->stmt_query($bill_goods_product_sql,'i',$_REQUEST['bill_goods_no']);

                    //生成短信内容
                    $data_array=array(
                        '$operator'=> $G_SHOP->currentUserName,
                        '$distribution_name'=> $sys_query[0]['distribution_name'],
                        '$bill_code'=>$bill_code[0]->bill_code
                    );
                    //发送短信
                    $this->send_message('downBusScan_sms',$data_array,$sys_query[0]['mobile']);

                    //发送短信end

                    //发送邮件start
                    //编号名称 （邮件标题）
                    $sys_itemcategory='select itemCategoryName from  sys_itemcategory where itemCategoryID= ?';
                    $itemcategory_query=$G_SHOP->DBCA->stmt_query($sys_itemcategory,'i',18);
                    //查询发件人邮箱
                    $sys_item='select itemName from sys_item where itemCategoryID= ? and useFlg=?';
                    $item_query=$G_SHOP->DBCA->stmt_query($sys_item,'ii',18,1);
                    $message= $G_SHOP->currentUserName."下车扫描". $sys_query[0]['distribution_name']."订单".$bill_code[0]->bill_code."未通过。请后续处理。";
                    $mailArray=array(
                        'subject'=>$itemcategory_query[0]->itemCategoryName,      //标题
                        'to'=>$item_query,                                           //收件人
                        'message'=>$message,                                        //短信内容
                        'from'=>'allen.qiang@fistforward.com',                       //发件人
                        'fromName'  =>'MCAKE'                                     //发件名

                    );
                    if($item_query){
                        $this->send_emails($mailArray);
                    }

                     //发送邮件end


                    //记录下错车操作记录start

                    //加载操作记录类
                    quanli_include('module/base/bill/bill_downBusScan_miss.class.php');
                    //实例化操作记录类
                    $bill_downBuscan_miss=new bill_downBuscan_miss();
                    $user_master_sql='select distributionID from user_master where userID=?';
                    $master_query=$G_PGLOB->DBCA->stmt_query($user_master_sql,'s',$G_PGLOB->currentUserID);
                    $z=str_replace(',','',str_replace('44','',str_replace('41','',$master_query[0]->distributionID)));
                    $logArray=array(
                        'bill_code'=>$bill_code[0]->bill_code,                                  //订单编号
                        'bill_goods_no'=>$_REQUEST['bill_goods_no'],                           //订单商品流水号
                        'distribution_id_f'=>$z,                                                //下错这点ID
                        'distribution_id_t'=>$sys_query[0]['distribution_id'],               //正确站点ID
                        'content'=>date("Y-m-d H:i:s")."下车扫描未通过"                           //日志

                    );
                    $bill_downBuscan_miss->add($logArray);

                    //add by 20141030  allen.qiang FUN-BK-0016-订单下错站处理end

                    returnJsonData('您无该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单配送站权限,无法进行下车扫描操作','404');
                }
            }

        }


        //将头部查询条件与当前订单生产流水号匹配
        $data = $_REQUEST['formValues'];

        $res_eq = 0;//标记头部查询条件与当前订单生产流水号是否匹配 匹配 标记为0
        $error_msg = ''; //记录不匹配信息

        $operName = '';//操作名
        $pathName = ''; //轨迹名
        if( $_REQUEST['userFlg'] == 1){
            $operName = '质检入库';
            $pathName = '您的订单已入库';
        }else if( $_REQUEST['userFlg'] == 2){
            $operName = '上车扫描';
            $pathName = '您的订单已出库';
        }else{
            $operName = '下车扫描';
            $pathName = '您的订单已配送站收货';
        }

        if( $billGoods_array ){
            //配送日期
            if( $billGoods_array[0]['send_date'] == $data['send_date'] && $res_eq == 0 ){
                $res_eq = 0;
            }else{
                $res_eq =1;

                $error_msg .= '该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单与查询条件日期不匹配，无法进行' .$operName. '操作<br>';

            }

            //配送开始时间
            if(isset($data['send_start_time']) && !empty($data['send_start_time']) && $res_eq == 0 ){
                if($billGoods_array[0]['send_start_time'] >= $data['send_start_time']){
                    $res_eq =0;
                }else{
                    $res_eq =1;
                    $error_msg .= '该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单查询条件不在配送开始时间范围，无法进行' .$operName. '操作<br>';
                }
            }

            //配送结束时间
            if( isset($data['send_start_time_end']) && !empty($data['send_start_time_end']) && $res_eq == 0 ){
                if($billGoods_array[0]['send_start_time'] <= $data['send_start_time_end']){
                    $res_eq =0;
                }else{
                    $res_eq =1;
                    $error_msg .= '该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单查询条件不在配送结束时间范围，无法进行' .$operName. '操作<br>';
                }
            }

            //城市id
            if(isset($data['cityID']) && !empty($data['cityID']) && $res_eq == 0){
                if($billGoods_array[0]['cityID'] == $data['cityID']){
                    $res_eq =0;
                }else{
                    $res_eq =1;
                    $error_msg .= '该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单查询条件城市不匹配，无法进行' .$operName. '操作<br>';
                }
            }

            //配送站id
            if(isset($data['distribution_id']) && !empty($data['distribution_id']) && $res_eq == 0 ){
                if($billGoods_array[0]['distribution_id'] == $data['distribution_id']){
                    $res_eq =0;
                }else{
                    $res_eq =1;
                    $error_msg .= '该订单商品流水号[' .$_REQUEST['bill_goods_no']. ']查询条件配送站不匹配，无法进行' .$operName. '操作<br>';
                }
            }
        }

        if( $res_eq == 0 ){
            //判断入库or上车扫描or下车扫描  1、为入库 2、上车扫描 3、下车扫描

            //查询订单主表状态
            $bill_master = new entity('bill_master');
            $bill_master->bill_no = $billGoods[0]['bill_no'];
            if (!$G_PGLOB->DBCA->fetch( $bill_master )){
                returnJsonData('暂无对应订单数据','404');
            }
            $bill_status = $bill_master->bill_status;

            if( $_REQUEST['userFlg'] == 1 ){

                if($billGoods[0]['is_voucher'] == 1){

                    if( $bill_status == 10 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已取消，无需进行质检入库操作','400');
                    }else if( $bill_status == 7 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已完成，无需进行质检入库操作','400');
                    }else if( $bill_status == 6 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已配送中，无需进行质检入库操作','400');
                    }else if( $bill_status == 5 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已下车扫描，无需进行质检入库操作','400');
                    }else if( $bill_status == 4 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已上车扫描，无需进行质检入库操作','400');
                    }else{
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>已入库，无需重复进行入库操作','400');
                    }

                }else if( $billGoods[0]['print_num'] > 0){
                    if( $bill_status == 10 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已取消，无需进行质检入库操作','400');
                    }else if( $bill_status == 7 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已完成，无需进行质检入库操作','400');
                    }else if( $bill_status == 6 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已配送中，无需进行质检入库操作','400');
                    }else if( $bill_status == 5 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已下车扫描，无需进行质检入库操作','400');
                    }else if( $bill_status == 4 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已上车扫描，无需进行质检入库操作','400');
                    }else if( $bill_status == 3 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已入库，无需进行质检入库操作','400');
                    }else if( $bill_status == 1 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产，无法进行质检入库操作','400');
                    }else if( $bill_status == 0 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产，无法进行质检入库操作','400');
                    }
                }else{
                     if( $bill_status == 1 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产，无法进行质检入库操作','400');
                    }else if( $bill_status == 0 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产，无法进行质检入库操作','400');
                    }

                }

            }else if($_REQUEST['userFlg'] == 2){

                if( $billGoods[0]['is_warehouse'] == 1 ){

                    if( $bill_status == 10 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已取消，无需进行上车扫描操作','400');
                    }else if( $bill_status == 7 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已完成，无需进行上车扫描操作','400');
                    }else if( $bill_status == 6 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已配送中，无需进行上车扫描操作','400');
                    }else if( $bill_status == 5 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已下车扫描，无需进行上车扫描操作','400');
                    }else{
                    	//mod yim.hu 20141119 FUN-BK-0032 切换语音 --start
                        //returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已上车扫描，无需进行上车扫描操作','400');
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已上车扫描，无需进行上车扫描操作','4000');                        
                        //mod yim.hu 20141119 FUN-BK-0032 切换语音 --end
                    }

                }else if( $billGoods[0]['is_voucher'] == 1 || $billGoods[0]['print_num'] > 0 ){
                    if( $bill_status == 10 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已取消，无需进行上车扫描操作','400');
                    }else if( $bill_status == 7 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已完成，无需进行上车扫描操作','400');
                    }else if( $bill_status == 6 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已配送中，无需进行上车扫描操作','400');
                    }else if( $bill_status == 5 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已下车扫描，无需进行上车扫描操作','400');
                    }else if( $bill_status == 4 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已上车扫描，无需进行上车扫描操作','400');
                    }
                    //mod yim.hu 20141119 FUN-BK-0032 切换语音 --start
//                  else if( $bill_status == 2 ){
//                      returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单生产状态，尚未质检入库，无法进行上车扫描操作','400');
//                  }if( $bill_status == 1 ){
//                      returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产、质检入库，无法进行上车扫描操作','400');
//                  }else if( $bill_status == 0 ){
//                      returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产、质检入库，无法进行上车扫描操作','400');
//                  }
                    else if( $bill_status == 2 ){
                    	returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单生产状态，尚未质检入库，无法进行上车扫描操作','4000');
                    }if( $bill_status == 1 ){
                    	returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产、质检入库，无法进行上车扫描操作','4000');
                    }else if( $bill_status == 0 ){
                    	returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产、质检入库，无法进行上车扫描操作','4000');
                    }                    
                    //mod yim.hu 20141119 FUN-BK-0032 切换语音 --end
                }else{
                	//mod yim.hu 20141119 FUN-BK-0032 切换语音 --start
//                  if( $bill_status == 1 ){
//                      returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产、质检入库，无法进行上车扫描操作','400');
//                  }else if( $bill_status == 0 ){
//                      returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产、质检入库，无法进行上车扫描操作','400');
//                  }
                    if( $bill_status == 1 ){
                    	returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产、质检入库，无法进行上车扫描操作','4000');
                    }else if( $bill_status == 0 ){
                    	returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产、质检入库，无法进行上车扫描操作','4000');
                    }                    
                    //mod yim.hu 20141119 FUN-BK-0032 切换语音 --end

                }

            }else{ //下车扫描

                //漏质检入库、上车扫描返回数据
                $forget_two_array = array(
                    'para' => 2,
                    'bill_goods_no'=>$_REQUEST['bill_goods_no']
                );
                //漏上车扫描返回数据
                $forget_one_array = array(
                    'para' => 1,
                    'bill_goods_no'=>$_REQUEST['bill_goods_no']
                );

                if( $billGoods[0]['is_busScan'] == 1 ){
                    if( $bill_status == 10 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已取消，无需进行下车扫描操作','400');
                    }else if( $bill_status == 7 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已完成，无需进行下车扫描操作','400');
                    }else if( $bill_status == 6 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已配送中，无需进行下车扫描操作','400');
                    }else {
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>已下车扫描，无需再进行下车扫描操作','400');
                    }

                }else if( $billGoods[0]['is_warehouse'] == 1 || $billGoods[0]['is_voucher'] == 1 || $billGoods[0]['print_num'] > 0 ){
                    if( $bill_status == 10 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已取消，无需进行下车扫描操作','400');
                    }else if( $bill_status == 7 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已完成，无需进行下车扫描操作','400');
                    }else if( $bill_status == 6 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已配送中，无需进行下车扫描操作','400');
                    }else if( $bill_status == 5 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已下车扫描，无需进行下车扫描操作','400');
                    }else if( $bill_status == 3 ){ ////可以直接下车扫描

                        $bill_goods_operate_forget = new entity('bill_goods_operate_forget');
                        $bill_goods_operate_forget->bill_goods_no = $_REQUEST['bill_goods_no'];
                        if ( $G_PGLOB->DBCA->fetch( $bill_goods_operate_forget ) ){
                            returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已生产、质检入库,尚未上车扫描，已进入漏操作审核界面，请联系站长','202','');
                        }else{
                            returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已生产、质检入库,尚未上车扫描，已进入漏操作审核界面，请联系站长','202',$forget_one_array);
                        }

                    }else if( $bill_status == 2 ){ //可以直接下车扫描

                        $bill_goods_operate_forget = new entity('bill_goods_operate_forget');
                        $bill_goods_operate_forget->bill_goods_no = $_REQUEST['bill_goods_no'];
                        if ( $G_PGLOB->DBCA->fetch( $bill_goods_operate_forget ) ){
                            returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已生产,尚未质检入库与上车扫描，已进入漏操作审核界面，请联系站长','202','');
                        }else{
                            returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单已生产,尚未质检入库与上车扫描，已进入漏操作审核界面，请联系站长','202',$forget_two_array);
                        }


                    }if( $bill_status == 1 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产，无法进行下车扫描操作','400');
                    }else if( $bill_status == 0 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产，无法进行下车扫描操作','400');
                    }
                }else{

                   if( $bill_status == 1 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单确认状态，尚未生产，无法进行下车扫描操作','400');
                    }else if( $bill_status == 0 ){
                        returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']<br>订单建立状态，尚未确认、生产，无法进行下车扫描操作','400');
                    }
                }

            }

        }

        try {

            //开启事务
            $G_PGLOB->DBCA->beginTransaction();
            if($res_eq == 0){ //与头部查询条件匹配

                //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                $product_code_count=0; //获得订单商品编码总数量
                $product_code_dfd_count=0; //获得代付单的特殊商品编码数量
                foreach($bill_goods_array as $goods_array){
                    $product_code_count++;
                    if(strstr(G_TPT_SKU,strtolower($goods_array['product_code']) )){ //判断是否是代付单的特殊商品编码
                        $product_code_dfd_count++;
                    }
                }
                //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end

                if($_REQUEST['userFlg'] == 1) {    //入库
                    /**
                     * ==================================================
                     * 订单商品生产表bill_goods_product添加入库信息start
                     * ==================================================
                     */
                    $bill_goods_product = new entity('bill_goods_product');
                    $bill_goods_product ->bill_goods_no = $_REQUEST['bill_goods_no'];
                    if(!$G_PGLOB->DBCA->fetch($bill_goods_product)){
                        throw new Exception( '订单商品不存在' , 404 );
                    }
                    $bill_goods_product->is_voucher = 1; //入库状态
                    $bill_goods_product->voucher_operator = $G_PGLOB->currentUserID;
                    $bill_goods_product->voucher_time = $G_PGLOB->sys_datetime;
                    $G_PGLOB->DBCA->save($bill_goods_product);

                    /**
                     * ====================================================
                     * 订单商品生产表bill_goods_product添加入库信息end
                     * ====================================================
                     */


                    /**
                     * ========================================
                     * 订单商品表bill_goods添加入库信息start
                     * ========================================
                     */
                    $bill_goods = new entity('bill_goods');
                    $bill_goods ->bill_goods_no = $_REQUEST['bill_goods_no'];
                    if(!$G_PGLOB->DBCA->fetch($bill_goods)){
                        throw new Exception( '订单商品不存在' , 404 );
                    }
                    $bill_goods->is_voucher = 1; //入库状态
                    $bill_goods->voucher_operator = $G_PGLOB->currentUserID;
                    $bill_goods->voucher_time = $G_PGLOB->sys_datetime;
                    $G_PGLOB->DBCA->save($bill_goods);
                    /**
                     * ========================================
                     * 订单商品表bill_goods添加入库信息end
                     * ========================================
                     */


                    /**
                     * ========================================
                     * 入库改变订单主表订单状态start
                     * ========================================
                     */
                    $bill_master = new entity('bill_master');
                    $bill_master->bill_no = $bill_goods->bill_no;
                    if (!$G_PGLOB->DBCA->fetch($bill_master)){
                        throw new Exception( '订单信息不存在' , 404 );
                    }


                    //判断订单商品总数量 与 订单商品入库数量 相等 订单商品已入库
                    if( $bill_master->bill_totalAmount == $bill_master->bill_voucher_amount ){
                        throw new Exception( '该订单商品已入库，无需入库操作' , 404 );
                    }

                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                    if( $product_code_count==$product_code_dfd_count || !strstr(G_TPT_SKU,strtolower($billGoods[0]['product_code']) )){//订单中仅有ptp03、ptp04、ptp05任意sku的 或不包括ptp03、ptp04、ptp05任意sku的订单
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end
                        $bill_master->bill_voucher_amount = $bill_master->bill_voucher_amount + 1; //入库时入库订单商品总数量+1
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                    }
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end

                    if ($bill_master->bill_totalAmount == $bill_master->bill_voucher_amount && $bill_master->bill_status == 2) {
                        $bill_master->bill_status = 3; //状态为入库
                    }

                    $G_PGLOB->DBCA->save($bill_master);

                    /**
                     * ========================================
                     * 入库改变订单主表订单状态end
                     * ========================================
                     */

                    /*=======================================================
                     * 写入日志 start
                     * ======================================================
                     */
                    quanli_include('module/base/customer/logHandler.class.php');
                    //实例日志类
                    $logHandler = new logHandler( $G_PGLOB->DBCA );

                    //订单商品总数量等于订单商品入库总数量，同时订单状态为“已入库”
                    if ($bill_master->bill_totalAmount == $bill_master->bill_voucher_amount && $bill_master->bill_status == 3) {

                        $log_array = array(
                            'logCategoryID' => 1,
                            'logItem' => $bill_master->bill_no,
                            'extend_1' => '订单已入库',
                            'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'已入库',
                            'extend_5' => 3,
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                            //'operator' => $G_PGLOB->currentUserID
                            'operator' => $G_PGLOB->currentUserName
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                        );

                    }else{

                        $log_array = array(
                            'logCategoryID' => 1,
                            'logItem' => $bill_master->bill_no,
                            'extend_1' => '',
                            'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'已入库',
                            'extend_5' => 2,
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                            //'operator' => $G_PGLOB->currentUserID
                            'operator' => $G_PGLOB->currentUserName
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                        );
                    }

                    $result_array = $logHandler->saveLogInfo( $log_array );
                    if ($result_array['code'] != 200){
                        throw new Exception( $result_array['message'], 400);
                    }

                    /*=======================================================
                     * 写入日志 end
                     * ======================================================
                     */

                    /*=======================================================
                    * 入库保存订单轨迹 start
                    * ======================================================
                    */
                    if ($bill_master->bill_totalAmount == $bill_master->bill_voucher_amount && $bill_master->bill_status == 3) {
                        quanli_include('module/base/bill/billEdit.class.php');

                        $bill_no = $bill_goods->bill_no;
                        $operator = $G_PGLOB->currentUserID;
                        $content = $pathName;

                        $billEdit = new billEdit( $G_PGLOB->DBCA);
                        $billTrace = $billEdit->addBillTrace( $bill_no, $operator, $content );
                        if ( !$billTrace ){
                            throw new Exception( '订单轨迹保存失败', 400);
                        }
                    }
                    /*=======================================================
                     * 入库保存订单轨迹 end
                     * ======================================================
                     */
                }else if($_REQUEST['userFlg'] == 2) {    // 上车扫描/出库

                    //add by 20141104 allen.qiang FUN-BK-0020-普陀站上车只报配送员姓名 start
                    if($billGoods_array[0]['distribution_id']==37){
                        $billGoods_array[0]['distribution_technician_audio'] = $this->get_DT_Audio($bill_master->distribution_technician_id);
                    }
                    //add by 20141104 allen.qiang FUN-BK-0020-普陀站上车只报配送员姓名 end

                    /**
                     * =====================================================
                     * 订单商品生产表bill_goods_product添加出库信息start
                     * =====================================================
                     */
                    $bill_goods_product = new entity('bill_goods_product');
                    $bill_goods_product ->bill_goods_no = $_REQUEST['bill_goods_no'];
                    if(!$G_PGLOB->DBCA->fetch($bill_goods_product)){
                        throw new Exception( '订单商品不存在' , 404 );
                    }

                    $bill_goods_product->is_warehouse = 1; //出库状态
                    $bill_goods_product->warehouse_operator = $G_PGLOB->currentUserID;
                    $bill_goods_product->warehouse_time = $G_PGLOB->sys_datetime;
                    $G_PGLOB->DBCA->save($bill_goods_product);

                    /**
                     * ========================================================
                     * 订单商品生产表bill_goods_product添加出库信息end
                     * ========================================================
                     */


                    /**
                     * ======================================================
                     * 订单商品表bill_goods添加出库信息start
                     * ======================================================
                     */
                    $bill_goods = new entity('bill_goods');
                    $bill_goods ->bill_goods_no = $_REQUEST['bill_goods_no'];
                    if(!$G_PGLOB->DBCA->fetch($bill_goods)){
                        throw new Exception( '订单商品不存在' , 404 );
                    }
                    $bill_goods->is_warehouse = 1; //出库状态
                    $bill_goods->warehouse_operator = $G_PGLOB->currentUserID;
                    $bill_goods->warehouse_time = $G_PGLOB->sys_datetime;
                    $G_PGLOB->DBCA->save($bill_goods);
                    /**
                     * ========================================
                     * 订单商品表bill_goods添加出库信息end
                     * ========================================
                     */


                    /**
                     * ========================================
                     * 出库改变订单主表订单状态start
                     * ========================================
                     */
                    $bill_master = new entity('bill_master');
                    $bill_master->bill_no = $bill_goods->bill_no;
                    if (!$G_PGLOB->DBCA->fetch($bill_master)){
                        throw new Exception( '订单信息不存在' , 404 );
                    }
                    //判断订单商品总数量 与 订单商品出库数量 相等 订单商品“已出库”
                    if( $bill_master->bill_totalAmount == $bill_master->bill_out_warehouse_amount ){
                        throw new Exception( '该订单商品已出库，无需出库操作' , 400 );
                    }

                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                    if( $product_code_count==$product_code_dfd_count || !strstr(G_TPT_SKU,strtolower($billGoods[0]['product_code']))){//订单中仅有ptp03、ptp04、ptp05任意sku的 或不包括ptp03、ptp04、ptp05任意sku的订单
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end
                        $bill_master->bill_out_warehouse_amount = $bill_master->bill_out_warehouse_amount + 1; //出库时出库订单商品总数量+1
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                    }
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end

                    if ($bill_master->bill_totalAmount == $bill_master->bill_out_warehouse_amount && $bill_master->bill_status == 3) {
                        $bill_master->bill_status = 4; //状态为“已出库”
                    }

                    $G_PGLOB->DBCA->save($bill_master);

                    /**
                     * ========================================
                     * 出库改变订单主表订单状态end
                     * ========================================
                     */


                    /*=======================================================
                    * 出库写入日志 start
                    * ======================================================
                    */
                    quanli_include('module/base/customer/logHandler.class.php');
                    //实例日志类
                    $logHandler = new logHandler( $G_PGLOB->DBCA );

                    //订单商品总数量等于订单商品入库总数量，同时订单状态为“已出库”
                    if ($bill_master->bill_totalAmount == $bill_master->bill_out_warehouse_amount && $bill_master->bill_status == 4) {

                        $log_array = array(
                            'logCategoryID' => 1,
                            'logItem' => $bill_master->bill_no,
                            'extend_1' => '订单已出库',
                            'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'已出库',
                            'extend_5' => 4,
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                            //'operator' => $G_PGLOB->currentUserID
                            'operator' => $G_PGLOB->currentUserName
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                        );

                    }else{

                        $log_array = array(
                            'logCategoryID' => 1,
                            'logItem' => $bill_master->bill_no,
                            'extend_1' => '',
                            'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'已出库',
                            'extend_5' => 3,
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                            //'operator' => $G_PGLOB->currentUserID
                            'operator' => $G_PGLOB->currentUserName
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                        );
                    }

                    $result_array = $logHandler->saveLogInfo( $log_array );
                    if ($result_array['code'] != 200){
                        throw new Exception( $result_array['message'], 400);
                    }

                    /*=======================================================
                     * 出库写入日志 end
                     * ======================================================
                     */

                    /*=======================================================
                    * 上车保存订单轨迹 start
                    * ======================================================
                    */
                    if ($bill_master->bill_totalAmount == $bill_master->bill_out_warehouse_amount && $bill_master->bill_status == 4) {
                        quanli_include('module/base/bill/billEdit.class.php');

                        $bill_no = $bill_goods->bill_no;
                        $operator = $G_PGLOB->currentUserID;
                        $content = $pathName;

                        $billEdit = new billEdit( $G_PGLOB->DBCA);
                        $billTrace = $billEdit->addBillTrace( $bill_no, $operator, $content );
                        if ( !$billTrace ){
                            throw new Exception( '订单轨迹保存失败', 400);
                        }
                    }
                    /*=======================================================
                     * 上车保存订单轨迹 end
                     * ======================================================
                     */


                }else {    // 下车扫描
                    /**
                     * ======================================================
                     * 订单商品生产表bill_goods_product添加下车信息start
                     * =======================================================
                     */
                    $bill_goods_product = new entity('bill_goods_product');
                    $bill_goods_product ->bill_goods_no = $_REQUEST['bill_goods_no'];
                    if(!$G_PGLOB->DBCA->fetch( $bill_goods_product )){
                        throw new Exception( '订单商品不存在' , 404 );
                    }

                    $bill_goods_product->is_busScan = 1; //下车状态
                    $bill_goods_product->busScan_operator = $G_PGLOB->currentUserID;
                    $bill_goods_product->busScan_time = $G_PGLOB->sys_datetime;
                    $G_PGLOB->DBCA->save($bill_goods_product);

                    /**
                     * =======================================================
                     * 订单商品生产表bill_goods_product添加下车信息end
                     * ========================================================
                     */


                    /**
                     * ========================================
                     * 订单商品表bill_goods添加下车信息start
                     * ========================================
                     */
                    $bill_goods = new entity('bill_goods');
                    $bill_goods ->bill_goods_no = $_REQUEST['bill_goods_no'];
                    if(!$G_PGLOB->DBCA->fetch($bill_goods)){
                        throw new Exception( '订单商品不存在' , 404 );
                    }
                    $bill_goods->is_busScan = 1; //下车状态
                    $bill_goods->busScan_operator = $G_PGLOB->currentUserID;
                    $bill_goods->busScan_time = $G_PGLOB->sys_datetime;
                    $G_PGLOB->DBCA->save($bill_goods);
                    /**
                     * ========================================
                     * 订单商品表bill_goods添加下车信息end
                     * ========================================
                     */


                    /**
                     * ========================================
                     * 下车改变订单主表订单状态start
                     * ========================================
                     */
                    $bill_master = new entity('bill_master');
                    $bill_master->bill_no = $bill_goods->bill_no;
                    if (!$G_PGLOB->DBCA->fetch($bill_master)){
                        throw new Exception( '订单信息不存在' , 404 );
                    }
                    //判断订单商品总数量 与 订单商品下车总数量 相等 订单商品“已配送站收货”
                    if( $bill_master->bill_totalAmount == $bill_master->bill_busScan_amount ){
                        throw new Exception( '该订单商品已配送站收货，无需下车扫描操作' , 400 );
                    }

                    //配送员名称
                    $billGoods_array[0]['distribution_technicia'] = $bill_master->distribution_technicia?$bill_master->distribution_technicia:'';

                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                    if( $product_code_count==$product_code_dfd_count || !strstr(G_TPT_SKU,strtolower($billGoods[0]['product_code']))){//订单中仅有ptp03、ptp04、ptp05任意sku的 或不包括ptp03、ptp04、ptp05任意sku的订单
                        //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end
                        $bill_master->bill_busScan_amount = $bill_master->bill_busScan_amount + 1; //下车时下车订单商品总数量+1
                        //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---start
                    }
                    //add by allen.qiang 20141105 FUN-BK-0014 代付单跳流程 ---end


                    if ($bill_master->bill_totalAmount == $bill_master->bill_busScan_amount && $bill_master->bill_status == 4) {

                        $bill_master->bill_status = 5; //状态为“配送站收货”

                        //加载短信类
                        quanli_include('module/base/common/quanliSms.class.php');
                        //加载会员类
                        quanli_require('module/base/customer/customerManage.class.php');
                        //加载配送站类
                        quanli_require('module/base/system/sysDistribution.class.php');
                        //加载配送员类
                        quanli_require('module/base/system/sysDistributionTechnician.class.php');

                        //实例化短信类
                        $quanliSms = new quanliSms();

                        //查询会员信息
                        $customerManage = new customerManage($G_PGLOB->DBCA);

                        $arg_arrays = array(
                            'custID' => $bill_master->custID
                        );
                        $customer_array = $customerManage->getCustomerInfo($arg_arrays);

                        //实例化配送员类
                        $sysDistributionTechnician = new sysDistributionTechnician();

                        //生成短信内容
                        $data_array = array(
                            '$bill_no' => $bill_master->bill_no,
                            '$bill_code' => $bill_master->bill_code,
                            '$operator' => $G_PGLOB->currentUserID,
                            '$custID' => $bill_master->custID,
                            '$date_time' => date("H:i:s",time()),
                            '$date' => date("Y-m-d",time()),
                            '$send_time' => $bill_master->send_date . ' ' . $bill_master->send_start_time,
                            '$distribution_name' => $bill_master->distribution_name
                        );
                        if($bill_master->distribution_technician_id){
                            $arg_array = array(
                                'distribution_technician_id' => $bill_master->distribution_technician_id
                            );

                            $technician_array = $sysDistributionTechnician->search( $arg_array );
                            $data_array['$distribution_technician'] = $bill_master->distribution_technicia . $technician_array[0]['mobile'];
                        }else{
                            $data_array['$distribution_technician'] = $bill_master->distribution_technicia;
                        }
                        if($customer_array){
                            $data_array['$cus_name'] = $customer_array[0]['custname'];
                            $data_array['$mobile'] = $customer_array[0]['mobile'];
                        }
                        if($bill_master->billType  == 9){

                            if($bill_master->sendTypeName == "自提" || $bill_master->sendTypeName == "站点自提"){
                                //实例化配送站设置类
                                $sysDistribution = new sysDistribution( );

                                //查询配送站
                                $arg_array = array(
                                    'distribution_id' => $bill_master->distribution_id,
                                );
                                $distribution_array = $sysDistribution->search( $arg_array );

                                if($distribution_array){
                                    $data_array['$phone'] = $distribution_array[0]['phone'];
                                    $data_array['$address'] = $distribution_array[0]['address'];
                                }

                                $sms_content = $quanliSms->getSmsContent( 'bill_noutoasiakas_get_off_bus', $data_array );
                                //发送短信
                                $quanliSms->sendSMS( decryptD($bill_master->deliver_mobile), $sms_content );
                            }else{
                                $sms_content = $quanliSms->getSmsContent( 'bill_get_off_bus', $data_array );
                                //发送短信
                                $quanliSms->sendSMS( decryptD($bill_master->deliver_mobile), $sms_content );
                            }
                        }
                        //清除该订单在bill_goods_product的数据
                        $delete_sql = 'DELETE FROM bill_goods_product WHERE bill_no = ? ';
                        $G_PGLOB->DBCA->stmt_query($delete_sql, 's', $bill_master->bill_no);

                    }

                    $G_PGLOB->DBCA->save($bill_master);



                    /**
                     * ========================================
                     * 改变订单主表订单状态end
                     * ========================================
                     */

                    /*=======================================================
                    * 配送站收货写入日志 start
                    * ======================================================
                    */
                    quanli_include('module/base/customer/logHandler.class.php');
                    //实例日志类
                    $logHandler = new logHandler( $G_PGLOB->DBCA );

                    //订单商品总数量等于订单商品下车总数量，同时订单状态为“已配送站收货”
                    if ($bill_master->bill_totalAmount == $bill_master->bill_busScan_amount && $bill_master->bill_status == 5) {

                        $log_array = array(
                            'logCategoryID' => 1,
                            'logItem' => $bill_master->bill_no,
                            'extend_1' => '配送站已收货',
                            'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'配送站已收货',
                            'extend_5' =>5,
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                            //'operator' => $G_PGLOB->currentUserID
                            'operator' => $G_PGLOB->currentUserName
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                        );

                    }else{

                        $log_array = array(
                            'logCategoryID' => 1,
                            'logItem' => $bill_master->bill_no,
                            'extend_1' => '',
                            'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'配送站已收货',
                            'extend_5' => 4,
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                            //'operator' => $G_PGLOB->currentUserID
                            'operator' => $G_PGLOB->currentUserName
                            //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                        );
                    }

                    $result_array = $logHandler->saveLogInfo( $log_array );
                    if ($result_array['code'] != 200){
                        throw new Exception( $result_array['message'], 400);
                    }

                    /*=======================================================
                     * 配送站收货写入日志 end
                     * ======================================================
                     */


                    /*=======================================================
                    * 下车保存订单轨迹 start
                    * ======================================================
                    */
                    if ($bill_master->bill_totalAmount == $bill_master->bill_busScan_amount && $bill_master->bill_status == 5) {
                        quanli_include('module/base/bill/billEdit.class.php');

                        $bill_no = $bill_goods->bill_no;
                        $operator = $G_PGLOB->currentUserID;
                        $content = $pathName;

                        $billEdit = new billEdit( $G_PGLOB->DBCA);
                        $billTrace = $billEdit->addBillTrace( $bill_no, $operator, $content );
                        if ( !$billTrace ){
                            throw new Exception( '订单轨迹保存失败', 400);
                        }
                    }
                    /*=======================================================
                     * 下车保存订单轨迹 end
                     * ======================================================
                     */

                    //获得配送员音频
                    $distribution_technician_id = $bill_master->distribution_technician_id; //配送员id
                    //实例化配送员类
                    $sysDistributionTechnician = new sysDistributionTechnician();
                    if( $distribution_technician_id > 0){
                        $arg_array =  array(
                            'distribution_technician_id'=>$distribution_technician_id
                        );
                        $distribution_technician_array = $sysDistributionTechnician->search( $arg_array );

                        if( $distribution_technician_array ){
                            $billGoods_array[0]['distribution_technician_audio'] = $distribution_technician_array[0]['audioShow'];
                        }
                    }

                }

                $billGoods_array[0]['billGoods_count'] = $billGoods_count?$billGoods_count:0;
                //提交事务
                $G_PGLOB->DBCA->commit();

                returnJsonData( 'ok', 200 ,$billGoods_array);
            }else{ //查询条件不匹配 写入错误记录表

                if( $_REQUEST['userFlg'] == 1 ){ //质检入库

                    $bill_goods = new entity('bill_goods');
                    $bill_goods->bill_goods_no = $_REQUEST['bill_goods_no'] ;
                    if ( !$G_PGLOB->DBCA->fetch( $bill_goods) ){
                        throw new Exception( '未找到该订单', 400);
                    }

                    $bill_goods_product = new entity('bill_goods_product');
                    $bill_goods_product->bill_goods_no = $_REQUEST['bill_goods_no'] ;
                    if ( $G_PGLOB->DBCA->fetch( $bill_goods_product ) ){
                        $bill_goods_product_error = new entity('bill_goods_product_error');

                        $bill_goods_product_error->creator = $G_PGLOB->currentUserID;
                        $bill_goods_product_error->createTime = $G_PGLOB->sys_datetime;
                        $bill_goods_product_error->bill_no = $bill_goods_product->bill_no;
                        $bill_goods_product_error->bill_code = $bill_goods_product->bill_code;
                        $bill_goods_product_error->bill_type = $bill_goods_product->bill_type;

                        $bill_goods_product_error->bill_goods_no = $bill_goods_product->bill_goods_no;
                        $bill_goods_product_error->cityID = $bill_goods_product->cityID;
                        $bill_goods_product_error->cityName = $bill_goods_product->cityName;
                        $bill_goods_product_error->billType = $bill_goods_product->billType;
                        $bill_goods_product_error->send_date = $bill_goods_product->send_date;

                        $bill_goods_product_error->send_start_time = $bill_goods_product->send_start_time;
                        $bill_goods_product_error->send_end_time = $bill_goods_product->send_end_time;
                        $bill_goods_product_error->distribution_id = $bill_goods_product->distribution_id;
                        $bill_goods_product_error->distribution_name = $bill_goods_product->distribution_name;
                        $bill_goods_product_error->is_urgent = $bill_goods_product->is_urgent;

                        $bill_goods_product_error->goods_postID = $bill_goods_product->goods_postID;
                        $bill_goods_product_error->product_code = $bill_goods_product->product_code;
                        $bill_goods_product_error->goods_name = $bill_goods_product->goods_name;
                        $bill_goods_product_error->goods_spec = $bill_goods_product->goods_spec;
                        $bill_goods_product_error->goods_amount = $bill_goods_product->goods_amount;

                        $bill_goods_product_error->tableware_amount = $bill_goods_product->tableware_amount;
                        $bill_goods_product_error->extra_tableware_amount=$bill_goods_product->extra_tableware_amount;
                        $bill_goods_product_error->candle_amount=$bill_goods_product->candle_amount;
                        $bill_goods_product_error->extra_candle_amount=$bill_goods_product->extra_candle_amount;
                        $bill_goods_product_error->birthday_card = $bill_goods_product->birthday_card;

                        $bill_goods_product_error->segmentation =$bill_goods_product->segmentation;
                        $bill_goods_product_error->goods_remark =$bill_goods_product->goods_remark;
                        $bill_goods_product_error->print_num =$bill_goods_product->print_num;
                        $bill_goods_product_error->print_operator =$bill_goods_product->print_operator;
                        $bill_goods_product_error->print_time =$bill_goods_product->print_time;

                        $bill_goods_product_error->is_voucher =$bill_goods_product->is_voucher;
                        $bill_goods_product_error->voucher_operator=$bill_goods_product->voucher_operator;
                        $bill_goods_product_error->voucher_time=$bill_goods_product->voucher_time;
                        $bill_goods_product_error->is_warehouse =$bill_goods_product->is_warehouse;
                        $bill_goods_product_error->warehouse_operator=$bill_goods_product->warehouse_operator;

                        $bill_goods_product_error->warehouse_time=$bill_goods_product->warehouse_time;
                        $bill_goods_product_error->is_busScan =$bill_goods_product->is_busScan;
                        $bill_goods_product_error->busScan_operator=$bill_goods_product->busScan_operator;
                        $bill_goods_product_error->busScan_time=$bill_goods_product->busScan_time;
                        $bill_goods_product_error->bill_status = 1;

                        $res = $G_PGLOB->DBCA->save( $bill_goods_product_error );
                    }



                }else if( $_REQUEST['userFlg'] == 2){ //上车扫描

                    $bill_goods = new entity('bill_goods');
                    $bill_goods->bill_goods_no = $_REQUEST['bill_goods_no'] ;
                    if ( !$G_PGLOB->DBCA->fetch( $bill_goods) ){
                        throw new Exception( '未找到该订单', 400);
                    }

                    $bill_goods_product = new entity('bill_goods_product');
                    $bill_goods_product->bill_goods_no = $_REQUEST['bill_goods_no'] ;
                    if ( $G_PGLOB->DBCA->fetch( $bill_goods_product ) ){
                        $bill_goods_product_error = new entity('bill_goods_product_error');

                        $bill_goods_product_error->creator = $G_PGLOB->currentUserID;
                        $bill_goods_product_error->createTime = $G_PGLOB->sys_datetime;
                        $bill_goods_product_error->bill_no = $bill_goods_product->bill_no;
                        $bill_goods_product_error->bill_code = $bill_goods_product->bill_code;
                        $bill_goods_product_error->bill_type = $bill_goods_product->bill_type;

                        $bill_goods_product_error->bill_goods_no = $bill_goods_product->bill_goods_no;
                        $bill_goods_product_error->cityID = $bill_goods_product->cityID;
                        $bill_goods_product_error->cityName = $bill_goods_product->cityName;
                        $bill_goods_product_error->billType = $bill_goods_product->billType;
                        $bill_goods_product_error->send_date = $bill_goods_product->send_date;

                        $bill_goods_product_error->send_start_time = $bill_goods_product->send_start_time;
                        $bill_goods_product_error->send_end_time = $bill_goods_product->send_end_time;
                        $bill_goods_product_error->distribution_id = $bill_goods_product->distribution_id;
                        $bill_goods_product_error->distribution_name = $bill_goods_product->distribution_name;
                        $bill_goods_product_error->is_urgent = $bill_goods_product->is_urgent;

                        $bill_goods_product_error->goods_postID = $bill_goods_product->goods_postID;
                        $bill_goods_product_error->product_code = $bill_goods_product->product_code;
                        $bill_goods_product_error->goods_name = $bill_goods_product->goods_name;
                        $bill_goods_product_error->goods_spec = $bill_goods_product->goods_spec;
                        $bill_goods_product_error->goods_amount = $bill_goods_product->goods_amount;

                        $bill_goods_product_error->tableware_amount = $bill_goods_product->tableware_amount;
                        $bill_goods_product_error->extra_tableware_amount=$bill_goods_product->extra_tableware_amount;
                        $bill_goods_product_error->candle_amount=$bill_goods_product->candle_amount;
                        $bill_goods_product_error->extra_candle_amount=$bill_goods_product->extra_candle_amount;
                        $bill_goods_product_error->birthday_card = $bill_goods_product->birthday_card;

                        $bill_goods_product_error->segmentation =$bill_goods_product->segmentation;
                        $bill_goods_product_error->goods_remark =$bill_goods_product->goods_remark;
                        $bill_goods_product_error->print_num =$bill_goods_product->print_num;
                        $bill_goods_product_error->print_operator =$bill_goods_product->print_operator;
                        $bill_goods_product_error->print_time =$bill_goods_product->print_time;

                        $bill_goods_product_error->is_voucher =$bill_goods_product->is_voucher;
                        $bill_goods_product_error->voucher_operator=$bill_goods_product->voucher_operator;
                        $bill_goods_product_error->voucher_time=$bill_goods_product->voucher_time;
                        $bill_goods_product_error->is_warehouse =$bill_goods_product->is_warehouse;
                        $bill_goods_product_error->warehouse_operator=$bill_goods_product->warehouse_operator;

                        $bill_goods_product_error->warehouse_time=$bill_goods_product->warehouse_time;
                        $bill_goods_product_error->is_busScan =$bill_goods_product->is_busScan;
                        $bill_goods_product_error->busScan_operator=$bill_goods_product->busScan_operator;
                        $bill_goods_product_error->busScan_time=$bill_goods_product->busScan_time;
                        $bill_goods_product_error->bill_status = 2;

                        $res = $G_PGLOB->DBCA->save( $bill_goods_product_error );
                    }



                }else{ //下车扫描

                    $bill_goods = new entity('bill_goods');
                    $bill_goods->bill_goods_no = $_REQUEST['bill_goods_no'] ;
                    if ( !$G_PGLOB->DBCA->fetch( $bill_goods) ){
                        throw new Exception( '未找到该订单', 400);
                    }

                    $bill_goods_product = new entity('bill_goods_product');
                    $bill_goods_product->bill_goods_no = $_REQUEST['bill_goods_no'] ;
                    if ( $G_PGLOB->DBCA->fetch( $bill_goods_product ) ){
                        $bill_goods_product_error = new entity('bill_goods_product_error');

                        $bill_goods_product_error->creator = $G_PGLOB->currentUserID;
                        $bill_goods_product_error->createTime = $G_PGLOB->sys_datetime;
                        $bill_goods_product_error->bill_no = $bill_goods_product->bill_no;
                        $bill_goods_product_error->bill_code = $bill_goods_product->bill_code;
                        $bill_goods_product_error->bill_type = $bill_goods_product->bill_type;

                        $bill_goods_product_error->bill_goods_no = $bill_goods_product->bill_goods_no;
                        $bill_goods_product_error->cityID = $bill_goods_product->cityID;
                        $bill_goods_product_error->cityName = $bill_goods_product->cityName;
                        $bill_goods_product_error->billType = $bill_goods_product->billType;
                        $bill_goods_product_error->send_date = $bill_goods_product->send_date;

                        $bill_goods_product_error->send_start_time = $bill_goods_product->send_start_time;
                        $bill_goods_product_error->send_end_time = $bill_goods_product->send_end_time;
                        $bill_goods_product_error->distribution_id = $bill_goods_product->distribution_id;
                        $bill_goods_product_error->distribution_name = $bill_goods_product->distribution_name;
                        $bill_goods_product_error->is_urgent = $bill_goods_product->is_urgent;

                        $bill_goods_product_error->goods_postID = $bill_goods_product->goods_postID;
                        $bill_goods_product_error->product_code = $bill_goods_product->product_code;
                        $bill_goods_product_error->goods_name = $bill_goods_product->goods_name;
                        $bill_goods_product_error->goods_spec = $bill_goods_product->goods_spec;
                        $bill_goods_product_error->goods_amount = $bill_goods_product->goods_amount;

                        $bill_goods_product_error->tableware_amount = $bill_goods_product->tableware_amount;
                        $bill_goods_product_error->extra_tableware_amount=$bill_goods_product->extra_tableware_amount;
                        $bill_goods_product_error->candle_amount=$bill_goods_product->candle_amount;
                        $bill_goods_product_error->extra_candle_amount=$bill_goods_product->extra_candle_amount;
                        $bill_goods_product_error->birthday_card = $bill_goods_product->birthday_card;

                        $bill_goods_product_error->segmentation =$bill_goods_product->segmentation;
                        $bill_goods_product_error->goods_remark =$bill_goods_product->goods_remark;
                        $bill_goods_product_error->print_num =$bill_goods_product->print_num;
                        $bill_goods_product_error->print_operator =$bill_goods_product->print_operator;
                        $bill_goods_product_error->print_time =$bill_goods_product->print_time;

                        $bill_goods_product_error->is_voucher =$bill_goods_product->is_voucher;
                        $bill_goods_product_error->voucher_operator=$bill_goods_product->voucher_operator;
                        $bill_goods_product_error->voucher_time=$bill_goods_product->voucher_time;
                        $bill_goods_product_error->is_warehouse =$bill_goods_product->is_warehouse;
                        $bill_goods_product_error->warehouse_operator=$bill_goods_product->warehouse_operator;

                        $bill_goods_product_error->warehouse_time=$bill_goods_product->warehouse_time;
                        $bill_goods_product_error->is_busScan =$bill_goods_product->is_busScan;
                        $bill_goods_product_error->busScan_operator=$bill_goods_product->busScan_operator;
                        $bill_goods_product_error->busScan_time=$bill_goods_product->busScan_time;
                        $bill_goods_product_error->bill_status = 3;

                        $res = $G_PGLOB->DBCA->save( $bill_goods_product_error );
                    }

                }
                //提交事务
                $G_PGLOB->DBCA->commit();
                if( $res ){
                    returnJsonData($error_msg.'已被记录到订单商品生产记录表','201');
                }

            }

        } catch (Exception $e){

            //回滚事务
            $G_PGLOB->DBCA->rollBack();

            if ($e->getCode() > 0) {
                returnJsonData( $e->getMessage(),$e->getCode());
                return;
            } else {
                returnJsonData( '系统错误，请与管理员联系',500);
                return;
            }

        }

    }



    /**
     *
     * 订单详情
     */
    public function showDetail(){

        global $G_PGLOB;


        if(!isset($_REQUEST['para'], $_REQUEST['send_date'], $_REQUEST['distribution_id'])){

            returnJsonData('缺少参数,请审核后再操作',400);
        }

        if(!is_numeric($_REQUEST['para']) || !is_numeric($_REQUEST['distribution_id'])){

            returnJsonData('参数错误,请审核后再操作',400);
        }

        if( !is_date( $_REQUEST['send_date'] ) ){

            returnJsonData('参数错误,请审核后再操作',400);
        }

        //校验配送日期
        $billGoodsProduct = new billGoodsProduct();

        $arg_sendDate= array(
            'send_date'=>$_REQUEST['send_date']
        );
        $billGoodsProductArray = $billGoodsProduct->searchBillGoodsInfo( $arg_sendDate );

        if( !$billGoodsProductArray ){
            returnJsonData('参数错误,请审核后再操作',400);
        }

        $arg_distribution = array(
            'distribution_id'=>$_REQUEST['distribution_id']
        );
        //校验配送站
        $billGoodsProductInfo = $billGoodsProduct->searchBillGoodsInfo( $arg_distribution );
        if( !$billGoodsProductInfo ){
            returnJsonData('参数错误,请审核后再操作',400);
        }

        if( $_REQUEST['para'] == 1 ){ //审核

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];


        }else if( $_REQUEST['para'] == 2 ){ //已打印

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["print_num"] = 1;

        }else if( $_REQUEST['para'] == 3 ){ //已入库

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["is_voucher"] = 1;

        }else if( $_REQUEST['para'] == 4 ){ //已上车

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["is_warehouse"] = 1;

        }else if( $_REQUEST['para'] == 5 ){ //已下车

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["is_busScan"] = 1;

        }else if( $_REQUEST['para'] == 6 ){ //未入库

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["is_voucher"] = 0;

        }else if( $_REQUEST['para'] == 7 ){ //未上车

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["is_warehouse"] = 0;

        }else if( $_REQUEST['para'] == 8 ){ //未下车

            $_REQUEST["send_date"] = $_REQUEST['send_date'];
            $_REQUEST["distribution_id"] = $_REQUEST['distribution_id'];
            $_REQUEST["is_busScan"] = 0;

        }

        //add by allen.qiang 20141226 FUN-BK-0014 代付单跳流程-质检入库、上车扫描、下车扫描隐藏特殊商品 ---start
        $_REQUEST["G_DFD_SKU"] = "DFD";
        //add by allen.qiang 20141226 FUN-BK-0014 代付单跳流程-质检入库、上车扫描、下车扫描隐藏特殊商品 ---end

        //实例化订单生产表对象
        $billGoodsProduct_obj = new billGoodsProduct();
        $billGoodsProduct_array = $billGoodsProduct_obj->searchBillGoodsInfo( $_REQUEST );

        if( !$billGoodsProduct_array ){
            returnJsonData('暂无订单生产数据',400);
        }

        //查询结果
        $result_array = array(
            'page' => $_REQUEST['page'],
            'total' => $_REQUEST['count'],
            'rows' => array()
        );

        if ($billGoodsProduct_array) {
            foreach ($billGoodsProduct_array as $key=>&$goodsInfo) {

                //订单标示
                if($goodsInfo['is_urgent'] == 1){
                    $is_urgent = "加急";
                }else{
                    $is_urgent = "";
                }
                //del by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -start
                //add by allen.qiang 20140925 加字段“配送员”----start
                //取得订单配送员信息
                //$BilldistributionInfo_obj = new billSearch();
                //$BilldistributionInfo = $BilldistributionInfo_obj->searchBilldistributionInfo($goodsInfo['bill_code']);
                //add by allen.qiang 20140925 加字段“配送员”----end
                //del by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -end
                $result_array['rows'][] = array(
                    'id' => $goodsInfo['bill_goods_no'],
                    'cell' => array(
                        $key+1,
                        $goodsInfo['cityName'],
                        $is_urgent,
                        $goodsInfo['billType'],
                        $goodsInfo['send_date'],
                        $goodsInfo['send_start_time'],
                        $goodsInfo['send_end_time'],
                        $goodsInfo['createTime'],
                        $goodsInfo['print_num'],
                        (string)$goodsInfo['bill_code'],
                        //add by allen.qiang 20140925 加字段“配送员”----start
                        //mod by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -start
                        //$BilldistributionInfo['distribution_technicia'],
                        $goodsInfo['distribution_technicia'],
                        //mod by allen.qiang 2014-1030 FUN-BK-0015-下车扫描界面详情框排序功能 -end
                        //add by allen.qiang 20140925 加字段“配送员”----end
                        (string)$goodsInfo['bill_goods_no'],
                        $goodsInfo['distribution_name'],
                        $goodsInfo['product_code'],
                        $goodsInfo['goods_name'],
                        $goodsInfo['goods_spec'],
                        $goodsInfo['goods_amount'],
                        $goodsInfo['tableware_amount']?$goodsInfo['tableware_amount']:'',
                        $goodsInfo['birthday_card'],
                        $goodsInfo['segmentation']?$goodsInfo['segmentation']:'',
                        $goodsInfo['goods_remark']

                    )
                );
            }
        }

        echo json_encode($result_array);
    }

    /*
     *
     * 生产or入库后直接下车扫描
     */
    private function execOutBus() {

        global $G_PGLOB;

        if(!isset($_REQUEST['bill_goods_no']) || empty($_REQUEST['bill_goods_no'])){
            returnJsonData('缺少参数','400');
        }

        //实例化订单商品生产表查询类
        $billGoodsProduct = new billGoodsProduct();

        //订单商品流水号参数
        $arg_array = array(
            'bill_goods_no'=>$_REQUEST['bill_goods_no']
        );

        //调用查询订单商品生产表方法
        $billGoods_array = $billGoodsProduct->searchBillGoodsInfo( $arg_array );

        //调用查询订单商品表方法
        $billGoods = $billGoodsProduct->searchBillGoods( $arg_array );

        //获得配送站信息
        if( $billGoods_array ){
            $distribution_id = $billGoods_array[0]['distribution_id'];

            //实例化配送站类
            $sysDistribution = new sysDistribution();
            if( $distribution_id >0 ){
                $arg_array = array(
                    'distribution_id'=>$distribution_id
                );
                $sysDistribution_array = $sysDistribution->search( $arg_array );

                if( $sysDistribution_array ){
                    $audio = $sysDistribution_array[0]['audio'];//配送站音频地址
                    $billGoods_array[0]['distribution_audio'] = $audio;
                }
            }

        }

        if( !$billGoods ){
            returnJsonData('暂无该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单商品数据','400');
        }

        if( $billGoods_array[0]['is_busScan'] == 1){
            returnJsonData('该商品流水号[' .$_REQUEST['bill_goods_no']. ']订单已下车扫描，无需再次进行下车扫描操作','400');
        }

        try {
            //开启事务
            $G_PGLOB->DBCA->beginTransaction();

            /**
             * ======================================================
             * 订单商品生产表bill_goods_product添加下车信息start
             * =======================================================
             */
            $bill_goods_product = new entity('bill_goods_product');
            $bill_goods_product ->bill_goods_no = $_REQUEST['bill_goods_no'];
            if(!$G_PGLOB->DBCA->fetch( $bill_goods_product )){
                throw new Exception( '订单商品不存在' , 404 );
            }

            $bill_goods_product->is_busScan = 1; //下车状态
            $bill_goods_product->busScan_operator = $G_PGLOB->currentUserID;
            $bill_goods_product->busScan_time = $G_PGLOB->sys_datetime;
            $G_PGLOB->DBCA->save($bill_goods_product);

            /**
             * =======================================================
             * 订单商品生产表bill_goods_product添加下车信息end
             * ========================================================
             */


            /**
             * ========================================
             * 订单商品表bill_goods添加下车信息start
             * ========================================
             */
            $bill_goods = new entity('bill_goods');
            $bill_goods ->bill_goods_no = $_REQUEST['bill_goods_no'];
            if(!$G_PGLOB->DBCA->fetch($bill_goods)){
                throw new Exception( '订单商品不存在' , 404 );
            }
            $bill_goods->is_busScan = 1; //下车状态
            $bill_goods->busScan_operator = $G_PGLOB->currentUserID;
            $bill_goods->busScan_time = $G_PGLOB->sys_datetime;
            $G_PGLOB->DBCA->save($bill_goods);
            /**
             * ========================================
             * 订单商品表bill_goods添加下车信息end
             * ========================================
             */


            /**
             * ========================================
             * 下车改变订单主表订单状态start
             * ========================================
             */
            $bill_master = new entity('bill_master');
            $bill_master->bill_no = $bill_goods->bill_no;
            if (!$G_PGLOB->DBCA->fetch($bill_master)){
                throw new Exception( '订单信息不存在' , 404 );
            }
            //判断订单商品总数量 与 订单商品下车总数量 相等 订单商品“已配送站收货”
            if( $bill_master->bill_totalAmount == $bill_master->bill_busScan_amount ){
                throw new Exception( '该订单商品已配送站收货，无需下车扫描操作' , 400 );
            }

            //配送员名称
            $billGoods_array[0]['distribution_technicia'] = $bill_master->distribution_technicia?$bill_master->distribution_technicia:'';

            if( $bill_master->bill_totalAmount > $bill_master->bill_busScan_amount){
                $bill_master->bill_busScan_amount = $bill_master->bill_busScan_amount + 1; //下车时下车订单商品总数量+1
            }

            if ( $bill_master->bill_totalAmount == $bill_master->bill_busScan_amount ) {

                $bill_master->bill_status = 5; //状态为“配送站收货”

                //加载短信类
                quanli_include('module/base/common/quanliSms.class.php');
                //加载会员类
                quanli_require('module/base/customer/customerManage.class.php');
                //加载配送站类
                quanli_require('module/base/system/sysDistribution.class.php');
                //加载配送员类
                quanli_require('module/base/system/sysDistributionTechnician.class.php');

                //实例化短信类
                $quanliSms = new quanliSms();

                //查询会员信息
                $customerManage = new customerManage($G_PGLOB->DBCA);

                $arg_arrays = array(
                    'custID' => $bill_master->custID
                );

                $customer_array = $customerManage->getCustomerInfo($arg_arrays);

                //实例化配送员类
                $sysDistributionTechnician = new sysDistributionTechnician();

                //生成短信内容
                $data_array = array(
                    '$bill_no' => $bill_master->bill_no,
                    '$bill_code' => $bill_master->bill_code,
                    '$operator' => $G_PGLOB->currentUserID,
                    '$custID' => $bill_master->custID,
                    '$date_time' => date("H:i:s",time()),
                    '$date' => date("Y-m-d",time()),
                    '$send_time' => $bill_master->send_date . ' ' . $bill_master->send_start_time,
                    '$distribution_name' => $bill_master->distribution_name
                );
                if($bill_master->distribution_technician_id){
                    $arg_array = array(
                        'distribution_technician_id' => $bill_master->distribution_technician_id
                    );

                    $technician_array = $sysDistributionTechnician->search( $arg_array );
                    $data_array['$distribution_technician'] = $bill_master->distribution_technicia .$technician_array[0]['mobile'];
                }else{
                    $data_array['$distribution_technician'] = $bill_master->distribution_technicia;
                }
                if($customer_array){
                    $data_array['$cus_name'] = $customer_array[0]['custname'];
                    $data_array['$mobile'] = $customer_array[0]['mobile'];
                }
                if($bill_master->billType  == 9){
                    if($bill_master->sendTypeName == "自提" || $bill_master->sendTypeName == "站点自提"){
                        //实例化配送站设置类
                        $sysDistribution = new sysDistribution( );

                        //查询配送站
                        $arg_array = array(
                            'distribution_id' => $bill_master->distribution_id,
                        );
                        $distribution_array = $sysDistribution->search( $arg_array );

                        if($distribution_array){
                            $data_array['$phone'] = $distribution_array[0]['phone'];
                            $data_array['$address'] = $distribution_array[0]['address'];
                        }

                        $sms_content = $quanliSms->getSmsContent( 'bill_noutoasiakas_get_off_bus', $data_array );
                        //发送短信
                        $quanliSms->sendSMS( decryptD($bill_master->deliver_mobile), $sms_content );
                    }else{
                        $sms_content = $quanliSms->getSmsContent( 'bill_get_off_bus', $data_array );
                        //发送短信
                        $quanliSms->sendSMS( decryptD($bill_master->deliver_mobile), $sms_content );
                    }
                }

            }

            $G_PGLOB->DBCA->save($bill_master);

            /**
             * ========================================
             * 改变订单主表订单状态end
             * ========================================
             */

            /*=======================================================
            * 配送站收货写入日志 start
            * ======================================================
            */
            quanli_include('module/base/customer/logHandler.class.php');
            //实例日志类
            $logHandler = new logHandler( $G_PGLOB->DBCA );

            //订单商品总数量等于订单商品下车总数量，同时订单状态为“已配送站收货”
            if ($bill_master->bill_totalAmount == $bill_master->bill_busScan_amount && $bill_master->bill_status == 5) {

                $log_array = array(
                    'logCategoryID' => 1,
                    'logItem' => $bill_master->bill_no,
                    'extend_1' => '配送站已收货',
                    'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'已配送站收货',
                    'extend_5' =>5,
                    //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                    //'operator' => $G_PGLOB->currentUserID
                    'operator' => $G_PGLOB->currentUserName
                    //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                );

            }else{

                $log_array = array(
                    'logCategoryID' => 1,
                    'logItem' => $bill_master->bill_no,
                    'extend_1' => '',
                    'extend_2' => $_REQUEST['bill_goods_no'].' '.$bill_goods_product->goods_name .' '.'已配送站收货',
                    'extend_5' => 5,
                    //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --start
                    //'operator' => $G_PGLOB->currentUserID
                    'operator' => $G_PGLOB->currentUserName
                    //mod by allen.qiang 20141022 系统中操作信息中“操作人”切换为中文 --end
                );
            }

            $result_array = $logHandler->saveLogInfo( $log_array );
            if ($result_array['code'] != 200){
                throw new Exception( $result_array['message'], 400);
            }

            /*=======================================================
             * 配送站收货写入日志 end
             * ======================================================
             */

            //获得配送员音频
            $distribution_technician_id = $bill_master->distribution_technician_id; //配送员id
            //实例化配送员类
            $sysDistributionTechnician = new sysDistributionTechnician();
            if( $distribution_technician_id >0 ){
                $arg_array =  array(
                    'distribution_technician_id'=>$distribution_technician_id
                );
                $distribution_technician_array = $sysDistributionTechnician->search( $arg_array );

                if( $distribution_technician_array ){
                    $billGoods_array[0]['distribution_technician_audio'] = $distribution_technician_array[0]['audioShow'];
                }
            }

            /*=======================================================
            * 保存订单轨迹 start
            * ======================================================
            */
            quanli_include('module/base/bill/billEdit.class.php');

            $bill_no = $bill_goods->bill_no;
            $operator = $G_PGLOB->currentUserID;
            $content = '您的订单已配送站收货';

            $billEdit = new billEdit( $G_PGLOB->DBCA);
            $billTrace = $billEdit->addBillTrace( $bill_no, $operator, $content );
            if ( !$billTrace ){
                throw new Exception( '订单轨迹保存失败', 400);
            }

            /*=======================================================
             * 保存订单轨迹 end
             * ======================================================
             */

            //清除该订单在bill_goods_product的数据
            $delete_sql = 'DELETE FROM bill_goods_product WHERE bill_goods_no = ? ';
            $G_PGLOB->DBCA->stmt_query($delete_sql, 's', $_REQUEST['bill_goods_no']);

            //提交事务
            $G_PGLOB->DBCA->commit();

            returnJsonData( 'ok', 200 ,$billGoods_array);


        } catch (Exception $e){

            //回滚事务
            $G_PGLOB->DBCA->rollBack();

            if ($e->getCode() > 0) {
                returnJsonData( $e->getMessage(),$e->getCode());
                return;
            } else {
                returnJsonData( '系统错误，请与管理员联系',500);
                return;
            }

        }

    }

    public function writeBillGoodsProductError(){

        global $G_PGLOB;

        $bill_goods = new entity('bill_goods');
        $bill_goods->bill_goods_no = $_REQUEST['bill_goods_no'] ;
        if ( !$G_PGLOB->DBCA->fetch( $bill_goods) ){
            returnJsonData( '未找到该订单', 400);
        }

        $bill_goods_product = new entity('bill_goods_product');
        $bill_goods_product->bill_goods_no = $_REQUEST['bill_goods_no'] ;
        if ( $G_PGLOB->DBCA->fetch( $bill_goods_product ) ){
            $bill_goods_product_error = new entity('bill_goods_product_error');

            $bill_goods_product_error->creator = $G_PGLOB->currentUserID;
            $bill_goods_product_error->createTime = $G_PGLOB->sys_datetime;
            $bill_goods_product_error->bill_no = $bill_goods_product->bill_no;
            $bill_goods_product_error->bill_code = $bill_goods_product->bill_code;
            $bill_goods_product_error->bill_type = $bill_goods_product->bill_type;

            $bill_goods_product_error->bill_goods_no = $bill_goods_product->bill_goods_no;
            $bill_goods_product_error->cityID = $bill_goods_product->cityID;
            $bill_goods_product_error->cityName = $bill_goods_product->cityName;
            $bill_goods_product_error->billType = $bill_goods_product->billType;
            $bill_goods_product_error->send_date = $bill_goods_product->send_date;

            $bill_goods_product_error->send_start_time = $bill_goods_product->send_start_time;
            $bill_goods_product_error->send_end_time = $bill_goods_product->send_end_time;
            $bill_goods_product_error->distribution_id = $bill_goods_product->distribution_id;
            $bill_goods_product_error->distribution_name = $bill_goods_product->distribution_name;
            $bill_goods_product_error->is_urgent = $bill_goods_product->is_urgent;

            $bill_goods_product_error->goods_postID = $bill_goods_product->goods_postID;
            $bill_goods_product_error->product_code = $bill_goods_product->product_code;
            $bill_goods_product_error->goods_name = $bill_goods_product->goods_name;
            $bill_goods_product_error->goods_spec = $bill_goods_product->goods_spec;
            $bill_goods_product_error->goods_amount = $bill_goods_product->goods_amount;

            $bill_goods_product_error->tableware_amount = $bill_goods_product->tableware_amount;
            $bill_goods_product_error->extra_tableware_amount=$bill_goods_product->extra_tableware_amount;
            $bill_goods_product_error->candle_amount=$bill_goods_product->candle_amount;
            $bill_goods_product_error->extra_candle_amount=$bill_goods_product->extra_candle_amount;
            $bill_goods_product_error->birthday_card = $bill_goods_product->birthday_card;

            $bill_goods_product_error->segmentation =$bill_goods_product->segmentation;
            $bill_goods_product_error->goods_remark =$bill_goods_product->goods_remark;
            $bill_goods_product_error->print_num =$bill_goods_product->print_num;
            $bill_goods_product_error->print_operator =$bill_goods_product->print_operator;
            $bill_goods_product_error->print_time =$bill_goods_product->print_time;

            $bill_goods_product_error->is_voucher =$bill_goods_product->is_voucher;
            $bill_goods_product_error->voucher_operator=$bill_goods_product->voucher_operator;
            $bill_goods_product_error->voucher_time=$bill_goods_product->voucher_time;
            $bill_goods_product_error->is_warehouse =$bill_goods_product->is_warehouse;
            $bill_goods_product_error->warehouse_operator=$bill_goods_product->warehouse_operator;

            $bill_goods_product_error->warehouse_time=$bill_goods_product->warehouse_time;
            $bill_goods_product_error->is_busScan =$bill_goods_product->is_busScan;
            $bill_goods_product_error->busScan_operator=$bill_goods_product->busScan_operator;
            $bill_goods_product_error->busScan_time=$bill_goods_product->busScan_time;
            $bill_goods_product_error->bill_status = 4;

            $res = $G_PGLOB->DBCA->save( $bill_goods_product_error );

            if( $res ){
                returnJsonData('该商品订单流水号['.$_REQUEST['bill_goods_no'].']<br>订单未下车扫描，已被记录到订单商品生产记录表',201);
            }
        }


    }

    //跳流程操作下车扫描 信息记录到订单商品漏操作记录表bill_goods_operate_forget
    public function writeBillGoodsOperateForget(){

        global $G_PGLOB;

        $bill_goods = new entity('bill_goods');
        $bill_goods->bill_goods_no = $_REQUEST['bill_goods_no'] ;
        if ( !$G_PGLOB->DBCA->fetch( $bill_goods) ){
            returnJsonData( '未找到该订单', 400);
        }

        $bill_master = new entity('bill_master');
        $bill_master->bill_no = $bill_goods->bill_no;
        if (!$G_PGLOB->DBCA->fetch($bill_master)){
            returnJsonData( '订单信息不存在' , 404 );
        }

//        //加载短信类
//        quanli_include('module/base/common/quanliSms.class.php');
//
//        //加载配送站类
//        quanli_require('module/base/system/sysDistribution.class.php');
//        //实例化配送站设置类
//        $sysDistribution = new sysDistribution( );
//
//        //查询配送站
//        $arg_array = array(
//            'distribution_id' => $bill_master->distribution_id,
//        );
//        $distribution_array = $sysDistribution->search( $arg_array );
//
//        if($distribution_array){
//            $data_array['$phone'] = $distribution_array[0]['phone'];
//        }
//
//        if( $_REQUEST['forget_operate_flow'] == 1){
//            $remarks = '上车扫描';
//        }else{
//            $remarks = '质检入库、上车扫描';
//        }
//
//        //实例化短信类
//        $quanliSms = new quanliSms();
//
//        //生成短信内容
//        $data_array = array(
//            '$bill_no' => $bill_master->bill_no,
//            '$bill_code' => $bill_master->bill_code,
//            '$operator' => $G_PGLOB->currentUserID,
//            '$custID' => $bill_master->custID,
//            '$date_time' => date("H:i:s",time()),
//            '$date' => date("Y-m-d",time()),
//            '$send_time' => $bill_master->send_date . ' ' . $bill_master->send_start_time,
//            '$distribution_name' => $bill_master->distribution_name,
//            '$remark'=>$remarks
//        );
//        $sms_content = $quanliSms->getSmsContent( 'billGoodsOperateForget', $data_array );
//        //发送短信
//        $quanliSms->sendSMS($distribution_array[0]['mobile'], $sms_content ); //decryptD($bill_master->deliver_mobile)

        $bill_goods_product = new entity('bill_goods_product');
        $bill_goods_product->bill_goods_no = $_REQUEST['bill_goods_no'] ;
        if ( $G_PGLOB->DBCA->fetch( $bill_goods_product ) ){
            $bill_goods_operate_forget = new entity('bill_goods_operate_forget');

            $bill_goods_operate_forget->creator = $G_PGLOB->currentUserID;
            $bill_goods_operate_forget->createTime = $G_PGLOB->sys_datetime;
            $bill_goods_operate_forget->bill_no = $bill_goods_product->bill_no;
            $bill_goods_operate_forget->bill_code = $bill_goods_product->bill_code;
            $bill_goods_operate_forget->bill_type = $bill_goods_product->bill_type;

            $bill_goods_operate_forget->bill_goods_no = $bill_goods_product->bill_goods_no;
            $bill_goods_operate_forget->cityID = $bill_goods_product->cityID;
            $bill_goods_operate_forget->cityName = $bill_goods_product->cityName;
            $bill_goods_operate_forget->billType = $bill_goods_product->billType;
            $bill_goods_operate_forget->send_date = $bill_goods_product->send_date;

            $bill_goods_operate_forget->send_start_time = $bill_goods_product->send_start_time;
            $bill_goods_operate_forget->send_end_time = $bill_goods_product->send_end_time;
            $bill_goods_operate_forget->distribution_id = $bill_goods_product->distribution_id;
            $bill_goods_operate_forget->distribution_name = $bill_goods_product->distribution_name;
            $bill_goods_operate_forget->is_urgent = $bill_goods_product->is_urgent;

            $bill_goods_operate_forget->goods_postID = $bill_goods_product->goods_postID;
            $bill_goods_operate_forget->product_code = $bill_goods_product->product_code;
            $bill_goods_operate_forget->goods_name = $bill_goods_product->goods_name;
            $bill_goods_operate_forget->goods_spec = $bill_goods_product->goods_spec;
            $bill_goods_operate_forget->goods_amount = $bill_goods_product->goods_amount;

            $bill_goods_operate_forget->tableware_amount = $bill_goods_product->tableware_amount;
            $bill_goods_operate_forget->extra_tableware_amount=$bill_goods_product->extra_tableware_amount;
            $bill_goods_operate_forget->candle_amount=$bill_goods_product->candle_amount;
            $bill_goods_operate_forget->extra_candle_amount=$bill_goods_product->extra_candle_amount;
            $bill_goods_operate_forget->birthday_card = $bill_goods_product->birthday_card;

            $bill_goods_operate_forget->segmentation =$bill_goods_product->segmentation;
            $bill_goods_operate_forget->goods_remark =$bill_goods_product->goods_remark;
            $bill_goods_operate_forget->print_num =$bill_goods_product->print_num;
            $bill_goods_operate_forget->print_operator =$bill_goods_product->print_operator;
            $bill_goods_operate_forget->print_time =$bill_goods_product->print_time;

            $bill_goods_operate_forget->is_voucher =$bill_goods_product->is_voucher;
            $bill_goods_operate_forget->voucher_operator=$bill_goods_product->voucher_operator;
            $bill_goods_operate_forget->voucher_time=$bill_goods_product->voucher_time;
            $bill_goods_operate_forget->is_warehouse =$bill_goods_product->is_warehouse;
            $bill_goods_operate_forget->warehouse_operator=$bill_goods_product->warehouse_operator;

            $bill_goods_operate_forget->warehouse_time=$bill_goods_product->warehouse_time;
            $bill_goods_operate_forget->is_busScan =$bill_goods_product->is_busScan;
            $bill_goods_operate_forget->busScan_operator=$bill_goods_product->busScan_operator;
            $bill_goods_operate_forget->busScan_time=$bill_goods_product->busScan_time;

            $bill_goods_operate_forget->forget_operate_flow=$_REQUEST['forget_operate_flow'];

            $res = $G_PGLOB->DBCA->save( $bill_goods_operate_forget );

            if( $res ){
                returnJsonData('该商品订单流水号['.$_REQUEST['bill_goods_no'].']<br>订单商品已进入漏操作审核界面，请联系站长',200);
            }else{
                returnJsonData('记录操作错误',400);
            }
        }
    }

    /*
     *
     * 短信提示站长
     */
    public function notePrompt(){
        global $G_PGLOB;

        $bill_goods = new entity('bill_goods');
        $bill_goods->bill_goods_no = $_REQUEST['bill_goods_no'] ;
        if ( !$G_PGLOB->DBCA->fetch( $bill_goods) ){
            returnJsonData( '未找到该订单', 400);
        }

        $bill_master = new entity('bill_master');
        $bill_master->bill_no = $bill_goods->bill_no;
        if (!$G_PGLOB->DBCA->fetch($bill_master)){
            returnJsonData( '订单信息不存在' , 404 );
        }

        //加载短信类
        quanli_include('module/base/common/quanliSms.class.php');

        //加载配送站类
        quanli_require('module/base/system/sysDistribution.class.php');
        //实例化配送站设置类
        $sysDistribution = new sysDistribution( );

        //查询配送站
        $arg_array = array(
            'distribution_id' => $bill_master->distribution_id,
        );
        $distribution_array = $sysDistribution->search( $arg_array );

        if($distribution_array){
            $data_array['$phone'] = $distribution_array[0]['phone'];
        }

        if( $_REQUEST['forget_operate_flow'] == 1){
            $remarks = '上车扫描';
        }else{
            $remarks = '质检入库、上车扫描';
        }

        //实例化短信类
        $quanliSms = new quanliSms();

        //生成短信内容
        $data_array = array(
            '$bill_no' => $bill_master->bill_no,
            '$bill_code' => $bill_master->bill_code,
            '$operator' => $G_PGLOB->currentUserID,
            '$custID' => $bill_master->custID,
            '$date_time' => date("H:i:s",time()),
            '$date' => date("Y-m-d",time()),
            '$send_time' => $bill_master->send_date . ' ' . $bill_master->send_start_time,
            '$distribution_name' => $bill_master->distribution_name,
            '$remark'=>$remarks
        );
        $sms_content = $quanliSms->getSmsContent( 'billGoodsOperateForget', $data_array );
        //发送短信$distribution_array[0]['mobile']
        $quanliSms->sendSMS($distribution_array[0]['mobile'], $sms_content ); //decryptD($bill_master->deliver_mobile)

        returnJsonData('该商品订单流水号['.$_REQUEST['bill_goods_no'].']<br>订单商品已进入漏操作审核界面，请联系站长',200);
    }


    /*
     * 非本站订单操作记录
     * @package  ajax
     * @subpackage  backend
     * @author   allen.qiang <allen.qiang@fistforward.com>
     * 20141030 add by allen.qiang  FUN-BK-0016-订单下错站处理
     */
    public function bill_downBuscan_miss(){
        global $G_PGLOB;
        $user_master_sql='select distributionID from user_master where userID=?';
        $master_query=$G_PGLOB->DBCA->stmt_query($user_master_sql,'s',$G_PGLOB->currentUserID);
        $distributionID=$master_query[0]->distributionID;
        $beginTime=date("Y-m-d")." 00:00:00";
        $endTime=date("Y-m-d")." 23:59:59";
        $downBusScan_sql="select * from bill_downBusScan_miss where distribution_id_f in (?) and createTime> ? and createTime < ?  order by createTime asc";
        $log_query=$G_PGLOB->DBCA->stmt_query($downBusScan_sql,'sss',$distributionID,$beginTime,$endTime);
       $logArray=array();
        if(!empty($log_query)){
            foreach($log_query as $k=>$log){
                $user_sql='select trueName from user_master where userID=?';
                $user_info=$G_PGLOB->DBCA->stmt_query($user_sql,'s',$log->creator);
                $dis_sql="SELECT distribution_name FROM sys_distribution where distribution_id=?";
                $dis_info=$G_PGLOB->DBCA->stmt_query($dis_sql,'s',$log->distribution_id_f);
                $dis_info_2=$G_PGLOB->DBCA->stmt_query($dis_sql,'s',$log->distribution_id_t);
                $logArray[$k]['bill_code']=$log->bill_code;
                $logArray[$k]['bill_goods_no']=$log->bill_goods_no;
                $logArray[$k]['content']=$log->content;
                $logArray[$k]['distribution_id_f']=$dis_info[0]->distribution_name;
                $logArray[$k]['distribution_id_t']=$dis_info_2[0]->distribution_name;
                $logArray[$k]['creator']=$user_info[0]->trueName;
            }
        }
        returnJsonData($logArray,200);



    }

    /*
     * 发送短信
     * @package  ajax
     * @subpackage  backend
     * @author   allen.qiang<allen.qiang@fistforward.com>
     * 20141030 add by allen.qiang  FUN-BK-0016-订单下错站处理
     * $template 模板
     * $content 短信内容
     * $mobile 手机号
     */
    public function send_message($template='',$content='',$mobile=''){
        global $G_PGLOB;
        try{
            //加载短信类
            quanli_include('module/base/common/quanliSms.class.php');
            //实例化短信类
            $quanliSms = new quanliSms();
            $sms_content = $quanliSms->getSmsContent( $template, $content);
            $sms_result = $quanliSms->sendSMS( $mobile, $sms_content );//发送短信

         } catch (Exception $e){

            if ($e->getCode() > 0) {
            returnJsonData( $e->getMessage(),$e->getCode());
            return;
            } else {
                returnJsonData( '系统错误，请与管理员联系',500);
                return;
            }

        }

    }
    /*
     * 发送邮件
     * @package  ajax
     * @subpackage  backend
     * @author   allen.qiang<allen.qiang@fistforward.com>
     * 20141030 add by allen.qiang  FUN-BK-0016-订单下错站处理
     * $mailArray 邮件参数
     */

    public function send_emails($mailArray=''){
        global $G_PGLOB;
        try{
            //加载邮件类
            quanli_include('module/base/system/sendMail.class.php');
            //实例化邮件类
            $sendMail = new sendMail();
            $rest= $sendMail->send($mailArray);//发送邮件

        } catch (Exception $e){
            if ($e->getCode() > 0) {
                returnJsonData( $e->getMessage(),$e->getCode());
                return;
            } else {
                returnJsonData( '系统错误，请与管理员联系',500);
                return;
            }

        }

    }


 /*
 * get_DT_Audio 取得配送员音频
 * @package  ajax
 * @subpackage  backend
 * @author   allen.qiang<allen.qiang@fistforward.com>
 * $distribution_technician_id 配送员ID
 * add by 20141104 allen.qiang FUN-BK-0020-普陀站上车只报配送员姓名
 */
    private function get_DT_Audio($distribution_technician_id=0)
    {
        //实例化配送员类
        $sysDistributionTechnician = new sysDistributionTechnician();
        if( $distribution_technician_id > 0){
            $arg_array =  array(
                'distribution_technician_id'=>$distribution_technician_id
            );
            $distribution_technician_array = $sysDistributionTechnician->search( $arg_array );

            if( $distribution_technician_array ){
                return $distribution_technician_array[0]['audioShow'];
            }
        }
        return '';
    }
    //add by 20141104 allen.qiang FUN-BK-0020-普陀站上车只报配送员姓名 end

}
